var express = require('express')
const multer = require('multer')

// 设置上传的目录
const upload = multer({
    dest: './uploads/'
})
var router = express.Router()

// 导入控制器模块
const IndexController = require('../controller/IndexController.js')
const CateController = require('../controller/CateController.js')
const ArtController = require('../controller/ArtController.js')
const UserController = require('../controller/UserController.js')
const systemController = require('../controller/systemController.js')
const SetsysController = require('../controller/SetsysController.js')
const query = require('../model/query.js')

// 后台首页
router.get('/', IndexController.index)
router.get('/systemData', IndexController.systemData)
// 展示分类列表页面
router.get('/catelist', CateController.index)
router.get('/artlist', ArtController.index)
// 后台登录页
router.get('/login', IndexController.login)
router.get('/test', IndexController.test)
router.get('/apiData', IndexController.apiData)

// 修改密码
router.get('/change', IndexController.change)
// 分类列表数据接口
router.get('/cateData', CateController.cateData)
// 分类添加
router.get('/addCate',CateController.addCate);
// 系统设置添加
router.post('/addList',CateController.addList);
// 编辑分类的接口  
router.post('/updCateData', CateController.updCateData)

// 删除分类数据接口
router.post('/deleteCate', CateController.deleteCate)

// 登录接口
router.post('/userLogin', UserController.userLogin)

// 登出接口
router.post('/userLogout', UserController.userLogout)

// 更新用户信息
router.post('/updUserInfo', UserController.updUserInfo)

// 更新用户头像
router.post('/avatar', upload.single('file'), UserController.avatar)

// 统计分类文章总数
router.get('/cateCount', CateController.cateCount)

// 系统设置
router.get('/addSystem',systemController.addSystem);
router.get('/system',systemController.system);
router.get('/setData',systemController.setData);
router.get('/delSet/:id',systemController.delSet);
router.get('/upSystemData',systemController.upSystemData);
router.get('/addSet',systemController.addSet);
router.get('/systemData', IndexController.systemData);

//判断验证用户
router.post('/isUser', UserController.isUser)
router.post('/eaitpsd', UserController.eaitpsd)

// 展示添加文章的页面
router.get('/addArticle', ArtController.addArticle)

// 删除文章接口
router.post('/delArtData', ArtController.delArtData)

// 添加文章的接口
router.post('/addArtData', upload.single('pic'), ArtController.addArtData)

// 文章列表接口数据
router.get('/artData', ArtController.artData)

// 获取单条数据的接口
router.get('/fetchOneArt', ArtController.fetchOneArt)

// 编辑文章接口
router.post('/updArtData', upload.single('pic'), ArtController.updArtData)

// 添加文章列表
// router.get('/addArticle', ArtController.addArticle)
router.get('/editArt', ArtController.editArt)

// 系统设置
router.get('/setsys', SetsysController.setsys)

router.post('/logDditPic', upload.single('file'),SetsysController.logDditPic)

module.exports = router;